// 无乱成功和失败都会返回结果，不会走catch

function allsetlled(promises) {
  let len = promises.length
  let resulst = []
  if (!len) return
  return new Promise((resolve, reject) => {
    for (let i = 0; i < len; i++) {
      const p = promises[i]
      // 判断是否为promise
      if (p && typeof p.then === 'function') {
        p.then((data) => {
          resulst[i] = data
        }, (err) => {
          resulst[i] = err
        })
      } else {
        resulst[i] = p
      }
      if (resulst.length === len) {
        resolve(resulst)
      }
    }
  })

}

allsetlled([1,
  2,
  3,
  new Promise((resolve, reject) => {
    throw new Error('jsjsjsj')
  }),
  new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(100);
    }, 1000);
  })])
  .then((data) => {
    console.log(data);
  })
  .catch((err) => {
    console.log(err, "失败了");
  });
